package com.example.compose_componet.components


import android.annotation.SuppressLint
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.ExperimentalMaterial3Api

import androidx.compose.runtime.Composable
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.compose_componet.viewModel.WeViewModel

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BottomBar() {
    val viewModel: WeViewModel = viewModel()
    Row() {
        BottomItem(img =Icons.Filled.Home,
            title = "学习",
            Modifier.weight(1f).clickable { viewModel.selectIndex=0 },
            if(viewModel.selectIndex==0) Color(0xFF0066FF) else Color(0xFF22DD48))
        BottomItem(img =Icons.Filled.DateRange,
            title = "任务",
            Modifier.weight(1f).clickable { viewModel.selectIndex=1},
            if(viewModel.selectIndex==1) Color(0xFF0066FF) else Color(0xFF22DD48) )
        BottomItem(img =Icons.Filled.Person,
            title = "我的",
            Modifier.weight(1f).clickable { viewModel.selectIndex=2 },
            if(viewModel.selectIndex==2) Color(0xFF0066FF) else Color(0xFF22DD48))
    }

}

@Composable
fun BottomItem(img: ImageVector, title:String,modifier: Modifier = Modifier,tint:Color){
    Column(modifier.padding(vertical = 8.dp), horizontalAlignment = Alignment.CenterHorizontally) {
        Icon(imageVector = img, contentDescription =null ,tint=tint)
        Text(text =title , color = tint)
    }
}



